package com.zhong.gang.pda.db.user;

import android.content.Context;


public class UserUtils {
    private static UserUtils userUtils;
    private static UserDao userDao;

    public UserUtils(Context context) {
        userDao = new UserDao(context);
    }

    public static UserUtils getIntent(Context context) {
        if (userUtils == null || userDao == null) {
            userUtils = new UserUtils(context);
        }
        return userUtils;
    }

    public UserDao getUserDao() {
        return userDao;
    }

    /**
     * 保存数据
     *
     * @param userBean
     */
    public void saveUser(UserBean userBean,boolean loginStatus) {
        userDao.deleteAll();
        userBean.setLogin(loginStatus);
        userDao.save(userBean);
    }

    /**
     * 保存数据
     *
     * @param userBean
     */
    public void saveUser(UserBean userBean) {
        saveUser(userBean,true);
    }


    /**
     * 获取User
     *
     * @return
     */
    public UserBean getUser() {
        UserBean userBean = userDao.queryForFirst();
        if (userBean == null)
            userBean = new UserBean();
        return userBean;
    }
}
